What could be causing a Javascript out of memory error when processing large arrays